package leetcode.other;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author 李栋
 * @version 1.0.0
 * @className Test0103.java
 * @createTime 2021年07月25日 20:31:00
 */
public class Test0103 {

    private static final Logger logger = LoggerFactory.getLogger(Test0103.class);



    @Test
    public void test() {
        logger.info(replaceSpaces("Mr John Smith    ", 13));
    }

    public String replaceSpaces(String S, int length) {
        char[] chars = S.toCharArray();
        StringBuilder s = new StringBuilder();
        for (int i = 0; i < length; i++) {
            if (chars[i] == 32) {
                s.append("%20");
            } else {
                s.append(chars[i]);
            }
        }
        return String.valueOf(s);

    }
}
